<script type="text/javascript" src="../Public/Js/ajaxupload.3.6.js"></script>
<script type= "text/javascript">
    /*<![CDATA[*/
    $(document).ready(function(){
        var button		=	$('#ajax_upload_attach_button');
        var process		=	$('#ajax_upload_attach_process');
        $('#ajax_upload_attach_button').attr('disabled',false).html('上传附件').addClass('btn_b');
        new AjaxUpload(button,{
            action: U('group/Dir/upload') + '&gid={$gid}&ajax=1',
            name: 'uploadfile',
            onSubmit : function(file, ext)
            {
            	if (get_file_num() >= 3) {
					ui.error('最多只可以附带3个附件');
					return false;
            	}
                this.disable();
                process.val('正在上传...');
            },
            onComplete: function(file, response)
            {
                //alert(response);
                this.enable();

                //处理上传后的过程
                var responseData	=	eval('(' + response + ')');
                //alert(response);
                //alert(responseData.status);
                // 上传失败
                if (responseData.status) {
                    process.val('上传成功.');
                	attach_upload_success(responseData.info[0]);
                } else {
                    process.val('上传失败.');
                    ui.error(responseData.info);
                }
            }
        });

    });
    /*]]>*/

    var get_file_num = function()
    {
        var files = new Array();
        var file_num = 0;
        $.each($('#attach_upload_data input[name="attach[]"]'), function(i, n){
            var file = $(n).val();
            if (file != '') {
            	file_num++;
            }
        });
        return file_num;
    }

    //执行默认的callback方法
    function attach_upload_success(info)
    {
        var attachInfo = '<input class="attach'+info.id+'" type="hidden" name="attach[]" value="'+info.id+'"/>'+'<div><a class="attach'+info.id+'" href= javascript:void(0) onclick="deleteAttach('+info.id+')">[删除]</a><span class="attach'+info.id+'"> '+info.name+'</span></div>';
        $('#attach_upload_data').append(attachInfo);
    }

    function deleteAttach(attach){
        $('#attach_upload_data .attach'+attach).remove();
    }
</script>
<div id="attach_upload_widget">
<div id="attach_upload_data">
  <volist name="attach" id="data">
	<input class="attach{$data['id']}" type="hidden" name="attach[]" value="{$data['id']}" />
	<p>
	<a class="attach{$data['id']}" href="javascript:void(0)" onclick="deleteAttach({$data['id']})">[删除]</a>
    <if condition="$data['is_del']">
      <span class="attach{$data['id']}"><span style="text-decoration:line-through;">{$data['name']}</span>[<span style="color:#FF0000;">已被管理员删除</span>]</span>
    <else />
	  <span class="attach{$data['id']}">{$data['name']}</span>
    </if>
	</p>
  </volist>
</div>
    <div id="attach_upload_tool">
        <input id="ajax_upload_attach_process" disabled="disabled" class="text" style="margin-right:5px" />
        <button id="ajax_upload_attach_button" disabled="disabled" class="btn_w">载入中</button>
    </div>
</div>